# -*- coding = utf-8 -*-
# @Time : 2021/12/23 15:37
# @Author : 龙王赘婿_彪少
# @File : demo11.py
# @Software: PyCharm

# 放置图片
# 输入框与显示框
#

import sys
from PyQt5.QtWidgets import (QWidget, QHBoxLayout,
                             QLabel, QApplication,
                             QLineEdit)
from PyQt5.QtGui import QPixmap


class Example(QWidget):
    def __init__(self):
        super(Example, self).__init__()
        # self.init_01()
        self.init_02()
        self.SHOW()

    def init_01(self):
        hbox = QHBoxLayout(self)
        pixmap = QPixmap("butterfly.png")

        lbl = QLabel(self)
        lbl.setPixmap(pixmap)

        hbox.addWidget(lbl)
        self.setLayout(hbox)

        self.move(0, 0)
        self.setWindowTitle("Red Rock")
        self.show()

    def SHOW(self):
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle("PyQt")
        self.show()

    def init_02(self):
        self.lbl = QLabel(self)
        qle = QLineEdit(self)

        qle.move(60, 100)
        self.lbl.move(60, 40)

        qle.textChanged[str].connect(self.onChanged)

    def onChanged(self, text):
        self.lbl.setText(text)
        # 将控件的长度调整为文本的长度
        self.lbl.adjustSize()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())